package com.rwx;

import com.rwx.appcontext.Component1;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.io.Resource;

import java.lang.reflect.Field;
import java.util.Map;

@SpringBootApplication
public class MyJava04Spring01Application {

    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext context = SpringApplication.run(MyJava04Spring01Application.class, args);

        Field singletonObjects =
                DefaultSingletonBeanRegistry.class.getDeclaredField("singletonObjects");
        singletonObjects.setAccessible(true);
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        Map<String, Object> o = (Map<String, Object>) singletonObjects.get(beanFactory);
        o.entrySet().stream().filter(e-> e.getKey().startsWith("component"))
                        .forEach(e->{
                            System.out.println(e.getKey()+"~~~"+e.getValue());
                        });


//        context.getMessage("",null, Locale.CHINA);
        Resource[] resources = context.getResources("classpath*:META-INF/spring.factories");//aaa.properties
        for (Resource resource : resources) {
            System.out.println(resource);
        }


        System.out.println(context.getEnvironment().getProperty("java_home"));


        //context.publishEvent(new UserRegisteredEvent(context));//构造函数的参数是事件源，谁发送的事件

        context.getBean(Component1.class).register();

    }

}
